/*
	Stargate SENT for GarrysMod10
	Copyright (C) 2007  aVoN

	This program is free software: you can redistribute it and/or modify
	it under the terms of the GNU General Public License as published by
	the Free Software Foundation, either version 3 of the License, or
	(at your option) any later version.

	This program is distributed in the hope that it will be useful,
	but WITHOUT ANY WARRANTY; without even the implied warranty of
	MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
	GNU General Public License for more details.

	You should have received a copy of the GNU General Public License
	along with this program.  If not, see <http://www.gnu.org/licenses/>.
*/
-- FIXME: Todo - Rewrite this using "ANIM" like in "stargate_iris" sent.
ENT.Sequence = {};

--################# Supergate's - Dialling sequence @JDM12989
-- ATTENTION: The dialling time takes exactly 7 seconds with my gates (dialled in fast mode). When you code your own gates, make them take 7 seconds too!
-- You can check a dialling sequence's length with adding "print_r(delay)" to end of the stargate_base's ENT:RunAction() function
function ENT.Sequence:Dial(inbound,fast,fail)
	local action = self:New();
	local add = 0;
	--################# ALL DIALLING
	add = add + 2.5; -- The delay is necessary because the diallin below takes about 4.5 seconds with a delay of 0.1 second between each light
	action:Add({f=self.SetStatus,v={self,false,true,true},d=add}); -- The first true tells, "we are in use", but the last tells wire NOT to indicate us as "Active". Otherwise, on a slow dial-in, a gate becomes "Wire-Active" even if it's not currently dialling
	action:Add({f=self.SetStatus,v={self,false,true},d=0.2});
	action:Add({f=self.EmitSound,v={self.Entity,self.Sounds.Ring,90,math.random(98,103)},d=0.1}); -- Ring Sound
	action:Add({f=self.Fire,v={self.Entity,"SetBodyGroup",1},d=0.2}); -- Activate the mainlight
	-- We are doing exactly 32 steps, so we are adding this delay now in every step.
	--action:Add({f=self.Fire,v={self.Entity,"SetBodyGroup",1},d=0.5}); -- Activate the gate's inbound lights
	action:Add({f=self.ActivateRing,v={self,true},d=0.2}); -- Start spinning zappy
	for i=1,32 do -- blue light in even intervals
		action:Add({f=self.RingLight,v={self,i,true},d=0.2});
		local snd = self.Sounds.Inbound;
		if (i % 4 == 0) then
			action:Add({f=self.SetWire,v={self,"Chevron",i},d=0}); -- Wire
			action:Add({f=self.EmitSound,v={self.Entity,snd,90,math.random(98,103)},d=0});
			action:Add({f=self.DHDSetChevron,v={self,i,0.05},d=0});
		end
	end
	action:Add({f=self.ActivateRing,v={self,false},d=0}); -- Stop the ring
	if(not fail) then
		action:Add({f=self.DHDSetChevron,v={self,8},d=0}); -- Activate near DHDs
	end
	return action;
end
